import React from "react";
import ReactDOM from "react-dom";
import App from "./App";
import "./index.css";
import PubSub from "pubsub-js";

import { renderWithQiankun, qiankunWindow, QiankunProps } from "vite-plugin-qiankun/dist/helper";
let root: any | null = null;

function render(props: QiankunProps) {
  const { container } = props;

  return ReactDOM.render(
    <App qiankun={props} />,
    (container
      ? container.querySelector("#root-micro")
      : document.querySelector("#root-micro")) as HTMLElement,
  );
}

if (!window.__POWERED_BY_QIANKUN__) {
  render({});
}

renderWithQiankun({
  mount(props) {
    root = render(props);
    // console.log("root",root)
    // props.onGlobalStateChange((state, prev)=>{
    //   console.log('state', state, 'prev', prev)
    // })
    // Actions.setActions(props)
  },
  bootstrap() {
    console.log('bootstrap')
  },
  unmount() {
    // PubSub.unsubscribe(subscriptionToken)
    ReactDOM.unmountComponentAtNode(document.querySelector("#root-micro")!)
  },
  update() {},
})